e[Single]
#ScriptVersion[2]
#Title[Sʏ1]

script_enemy_main{
	
	//IvVXYW
	let option1x = -64;
	let option1y =   0;
	let option2x =  64;
	let option2y =   0;
	
	@Initialize{
		//f[^
		InitializeData();
		InitializeAction();
		
		//Ctݒ
		SetLife( 2000 );
		//ʒuݒ
		//Warp( CenterX, MinY + 130, 40 );
		//_[W[gݒ
		SetDamageRate( 100, 100 );
		//蔻ݒ
		SetCollisionEx( 32, 16, false, 60 );
		//Gl~[}[J[
		SetEnemyMarker( true );
		
		//C^XNJn
		TMain();
	}
	
	@MainLoop{
		//yield[v
		yield;
	}
	
	@DrawLoop{
		//{X摜`
		SetGraphicScale( xscale, yscale );
		DrawBoss( imgBoss );
	}
	
	@Finalize{
		//ŏI
		FinalizeData();
	}
	
	/**
	 * C^XN
	 */
	task TMain(){
		//IvVWJ
		OptionControl();
		
		//60F(1b)҂
		FWait( 60 );
		
		//Ԑݒ
		SetTimer( 36 );
		
		//U
		alternative( difficult )
			case( "Easy" ){
				Atack_Easy();
			}
			case( "Normal" ){
				Atack_Normal();
			}
			case( "Panic" ){
				Atack_Panic();
			}
	}
	
	/**
	 * Easy UC^XN
	 */
	task Atack_Easy(){
	}
	
	/**
	 * Normal UC^XN
	 */
	task Atack_Normal(){
	}
	
	/**
	 * Panic UC^XN
	 */
	task Atack_Panic(){
		loop{
			Atack1();
			Atack2();
			
			FWait( 200 );
			
			ascent( i in 0..16 ){
				Shot1( GetX()           , GetY()           , 3.6, i * 360 / 16, PURPLE23, 20,    0, 65, 36 );
				Shot1( GetX() + option1x, GetY() + option1y, 3.6, i * 360 / 16, PURPLE23, 20,  2.8, 65, 36 );
				Shot1( GetX() + option2x, GetY() + option2y, 3.6, i * 360 / 16, PURPLE23, 20, -2.8, 65, 36 );
			}
			
			FWait( 90 );
			
			Warp( rand( MinX + 64, MaxX - 64 ), MinY + 100 + rand( -20, 20 ), 40 );
			
			FWait( 60 );
		}
	}
	
	task Atack1(){
		loop( 6 ){
			ShotGun( GetX(), GetY(), 7, GetAngleToPlayer(), PURPLE23, 12, 5, 1, 4.2, 2 );
			FWait( 40 );
		}
	}
	
	task Atack2(){
		let way = 16;
		let sway = 7;
		let span = 1.6;
		let speed = 2.8;
		let graph = 0;
		let angle = rand( 0, 360 );
		let sangle = 0;
		let wtime = 26;
		let turn = 1;
		let x = 0;
		let y = 0;
		
		loop( 12 ){
			if( turn == 1 ){
				x = GetX() + option1x;
				y = GetY() + option1y;
				graph = US_BALL_F_RED;
			}else{
				x = GetX() + option2x;
				y = GetY() + option2y;
				graph = US_BALL_F_BLUE;
			}
			
			angle += 360 / 8;
			if ( isDrawEffect ) {
				Explosion01( x, y, 12, 0.22, 90 );
			}
			ascent( i in 0..way ){
				ascent( j in 0..sway ){
					sangle = angle + i * 360 / way + ( ( -sway + 1 ) / 2 + j ) * span;
					CreateShot01( x, y, speed, sangle, graph, 0 );
				}
			}
			
			turn *= -1;
			wtime -= 2;
			speed *= 1.1;
			FWait( wtime );
		}
	}
	
	function ShotGun( x, y, speed, angle, graph, delay, num, way, span, grp ){
		let ang = 0;
		let spd = speed;
		let cspd = -speed / ( num * grp );
		
		loop( num ){
			ang = angle - ( way - 1 ) / 2 * span;
			ascent( i in 0..way ){
				CreateShot01( x, y, speed, ang, graph, delay );
				ang += span;
			}
			way += 1;
			speed += cspd;
		}
	}
	
	task Shot1( x, y, speed, angle, graph, delay, roll, wtime, way ){
		let count = 0;
		
		let obj = CreateObjShot( x, y, speed, angle, graph, delay );
		
		while( !Obj_BeDeleted( obj ) ){
			count += 1;
			if( count > wtime ){
				x = Obj_GetX( obj );
				y = Obj_GetY( obj );
				angle = GetGapAngle( x, y, GetPlayerX(), GetPlayerY() );
				
				ascent( i in 0..way ){
					CreateShot01( x, y, speed * 0.8, angle + i * 360 / way, graph, delay );
				}
				Obj_Delete( obj );
			}
			angle += roll;
			Obj_SetAngle( obj, angle );
			yield;
		}
	}
	
	/**
	 * IvV̐
	 */
	task OptionControl(){
		loop{
			GrowEffect( GetX() + option1x, GetY() + option1y, PURPLE01, 24, 23 );
			GrowEffect( GetX() + option2x, GetY() + option2y, PURPLE01, 24, 23 );
			
			yield;
		}
	}
	
	//XNvg̃CN[h
	#include_function ".\initialize.txt"
	#include_function ".\..\..\..\Library\lib_effect.txt"
}